package com.itheima.goods.controller;

import com.itheima.goods.pojo.Brand;
import com.itheima.goods.service.BrandService;
import entity.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
public class BrandController {


    @Autowired
    private BrandService brandService;


    @GetMapping("/brand")
    public Result findAll() {
        Result<Brand> result = brandService.findAll();
        return result;
    }


    @PostMapping("/brand")
    public Result add(@RequestBody Brand brand) {
        Result result = brandService.addBrand(brand);
        return result;
    }

    //分页查询
    @GetMapping("/brand/search/{page}/{size}")
    public Result findPage(@PathVariable("page") Integer page, @PathVariable("size") Integer size) {

        Result<Brand> result = brandService.findPage(page, size);
        return result;
    }

    //分页条件查询
    @PostMapping("/brand/search/{page}/{size}")
    public Result findPage1(@PathVariable("page") Integer page, @PathVariable("size") Integer size, @RequestBody Brand brand) {
        Result<Brand> result = brandService.TfindPage(page, size, brand);
        return result;
    }

    //根据id；查询
    @GetMapping("/brand/{id}")
    public Result findById(@PathVariable("id") Integer id) {
        return brandService.findById(id);
    }

    //修改brand数据
    @PutMapping("/brand/{id}")
    public Result updateById(@PathVariable("id") Integer id, @RequestBody Brand brand) {

        return brandService.updateById1(brand, id);
    }


    @DeleteMapping("/brand/{id}")
    public Result deleteById(@PathVariable("id") Integer id) {
        return brandService.deleteById(id);
    }


}
